-
Notifications
You must be signed in to change notification settings - Fork 165
system: Add create account helper #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
4c01fc7 to
4b87477
Compare
4b87477 to
05f74a9
Compare
| to: account, | ||
| lamports: required_lamports, | ||
| } | ||
| .invoke()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this .invoke_signed(signers)?; to support the case a PDA acts as the funding account for the transfer?
| Rent::get()?.minimum_balance(space) | ||
| }; | ||
|
|
||
| if account.lamports() == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about using hints from pinocchio::hint module?
i expect account is not exist, in the majority of cases
| if account.lamports() == 0 { | |
| if likely(account.lamports() == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about using hints from
pinocchio::hintmodule?i expect account is not exist, in the majority of cases
It made no difference in my tests. Also, I had a look at the asm and it seems the compiler is doing the right thing already. Did you notice a difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same for the lib (i didn't test it in the real app).
As a part of library it compiles in the expected instructions.
Just wanted to make extra sure this logic won't be miscompiled in the large program.
| let required_lamports = lamports.saturating_sub(account.lamports()); | ||
|
|
||
| // Transfer lamports from `payer` to `account` if needed. | ||
| if required_lamports > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same here can be applied, i believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here, no difference.
Problem
Creating accounts funded by a payer account is a common operation. In most cases, the logic needs to be replicated in different programs.
Solution
Add a helper to create accounts. The helper supports creating both PDA and non-PDA accounts.